package com.jk.service.impl;

import com.jk.bean.Tree;
import com.jk.mapper.TreeMapper;
import com.jk.service.TreeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TreeServiceImpl implements TreeService {

   @Resource
    private TreeMapper treeMapper;


    @Override
    public List<Tree> getTree() {

        List<Tree> list = treeMapper.getTree(0);
        getList(list);
        return list;
    }

    private void getList(List<Tree> list) {

        for(Tree tree : list){

            List<Tree> data = treeMapper.getTree(tree.getId());

            tree.setChildren(data);
        }
    }
}
